import { request } from "@umijs/max";

/** 分类列表 */
export async function listCategories() {
  return request<ProductType.CategoryList[]>("/product/category-list", {
    method: "POST",
  });
}

/** 分类列表 */
export async function typeCategories() {
  return request<ProductType.CategorySelectList[]>("/product/category-type", {
    method: "GET",
  });
}

/** 创建分类 */
export async function createCategory(data: ProductType.CategoryCreate) {
  return request("/product/category-add", {
    method: "POST",
    data,
  });
}

/** 更新分类 */
export async function updateCategory(data: ProductType.CategoryUpdate) {
  return request("/product/category-update", {
    method: "PUT",
    data,
  });
}

/** 删除分类 */
export async function deleteCategory(id: number) {
  return request(`/product/category-delete/${id}`, {
    method: "DELETE",
  });
}

/** 商品列表 */
export async function listManagement() {
  return request<API.PageResult<ProductType.ManagementList>>(
    "/product/management-list",
    {
      method: "POST",
    }
  );
}

/** 商品详情 */
export async function managementDetail(id: string) {
  return request<ProductType.ManagementDetail>("/product/management-detail", {
    method: "GET",
    params: { id: id },
  });
}

/** 创建签商品 */
export async function createManagement(data: ProductType.ManagementDetail) {
  return request("/product/management-add", {
    method: "POST",
    data,
  });
}

/** 更新商品 */
export async function updateManagement(data: ProductType.ManagementDetail) {
  return request("/product/management-update", {
    method: "PUT",
    data,
  });
}

/** 更新商品部分内容 */
export async function updateSelectiveManagement(
  data: ProductType.CategoryUpdate
) {
  return request("/product/management-update-selective", {
    method: "PUT",
    data,
  });
}

/** 删除商品 */
export async function deleteManagement(id: number) {
  return request(`/product/management-delete/${id}`, {
    method: "DELETE",
  });
}
